{include file="common/_header"}

<body>

<div class="x-body layui-anim layui-anim-up">
    <form class="layui-form">
        <input type="hidden" name="team_id" value="{$team.team_id}">

        <div>

            <div class="wine_div1">
                <div class="wine_div2">团队名称：</div>
                <div class="wine_div3">
                    <input type="text" width="300px" name="team_name" value="{$team.team_name}" lay-verify="required" autocomplete="off"
                           class="layui-input">
                </div>
            </div>


            <div class="wine_div1">
                <div class="wine_div2">团队联系电话：</div>
                <div class="wine_div3">
                    <input type="text" name="phone" autocomplete="off" class="layui-input" lay-verify="required"
                           value="{$team.phone}">
                </div>
            </div>


            <div class="wine_div1">
                <div class="wine_div2">团队简介（一句话）：</div>
                <div class="wine_div3">
                    <textarea rows="5" cols="30" class="layui-textarea"  name="description">{$team.description}</textarea>
                </div>
            </div>

            <div class="wine_div1">
                <div class="wine_div2">团队封面图：</div>
                <div class="wine_div3">
                    <button type="button" class="layui-btn" id="test1">上传图片</button><br>
                    <div class="layui-upload-list">
                        <p id="demoText"></p>
                        {if !empty($team.top_pic)}
                        <img class="layui-upload-img" id="demo1" width="100px" height="100px" src="/{$team.top_pic}" ondblclick="delimg(1)" style="margin-right:5px;">
                        <input type="hidden" name="top_pic" class="image1" value="{$team.top_pic}"  lay-verify="required">
                        {/if}
                    </div>
                </div>
            </div>

            <div class="wine_div1">
                <div class="wine_div2">排序：</div>
                <div class="wine_div3">
                    <input type="text" name="sort" autocomplete="off" class="layui-input" value="{$team.sort}" />
                </div>
            </div>

            <div class="wine_div1">
                <div class="wine_div2">状态：</div>
                <div class="wine_div3">
                    <select name="status">
                        <option value="1" {if $team.status== 1}selected{/if}>正常</option>
                        <option value="2" {if $team.status== 2}selected{/if}>下架</option>
                    </select>
                </div>
            </div>



            <div class="wine_div1">
                <div class="wine_div2">省：</div>
                <div class="wine_div3">
                    <select name="province_id" id="province" lay-filter="province">
                        <option value="">请选择省份</option>
                        {volist name="data.province" id="vo"}
                        <option value="{$vo.id}" {if $team.province_id == $vo.id}selected{/if}>{$vo.name}</option>
                        {/volist}
                    </select>
                </div>
            </div>


            <div class="wine_div1">
                <div class="wine_div2">市：</div>
                <div class="wine_div3">
                    <select name="city_id" id="city" lay-filter="province">
                        <option value="">请选择城市</option>
                        {volist name="data.city" id="vo"}
                        <option value="{$vo.id}" {if $team.city_id == $vo.id}selected{/if}>{$vo.name}</option>
                        {/volist}
                    </select>
                </div>
            </div>


            <div class="wine_div1">
                <div class="wine_div2">区：</div>
                <div class="wine_div3">
                    <select name="area_id" id="area" lay-filter="province">
                        <option value="">请选择区/县</option>
                        {volist name="data.area" id="vo"}
                        <option value="{$vo.id}" {if $team.area_id == $vo.id}selected{/if}>{$vo.name}</option>
                        {/volist}
                    </select>
                </div>
            </div>


            <div class="wine_div1">
                <div class="wine_div2">街道：</div>
                <div class="wine_div3">
                    <select name="street_id" id="street">
                        <option value="">请选择街道</option>
                        {volist name="data.street" id="vo"}
                        <option value="{$vo.id}" {if $team.street_id == $vo.id}selected{/if}>{$vo.name}</option>
                        {/volist}
                    </select>
                </div>
            </div>


        </div>


        <div style="margin-top: 50px; float: right; margin-right: 50px;">
            <button type="button" lay-submit lay-filter="add" class="layui-btn">立即提交</button>
        </div>
    </form>
</div>
</body>


<script>

    // 地区联动
    _region();

    function delimg(id){
        $('.layui-upload-list').find('#demo'+id).remove();
        $('.layui-upload-list').find('.image'+id).remove();
    }

    layui.use(['form', 'layer', 'layedit', 'upload'], function () {

        var form = layui.form;
        var layedit = layui.layedit;
        var up_url = "{:url('/main/ueditor')}";
        var url = window.location.origin+'/';

        var upload = layui.upload;
        var id = 1;
        var id2 = 1;
        var number = 0;
        //常规使用 - 普通图片上传
        //常规使用 - 普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            , url: '/main/upload' //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
            , before: function (obj) {
                number = $('.layui-upload-list').find('img').length;
                if(number > 1){
                    layer.msg('最多只能上传一张图片');
                    return false;
                }
            }
            ,done: function(res){
                console.log(res);
                if(number >= 3){return false;}
                //如果上传失败
                if(res.code == 1){

                    $('.layui-upload-list').find("img").remove();

                    $('.layui-upload-list').append('<img class="layui-upload-img" id="demo'+id+'" width="100px" height="100px" src="'+url+res.data.src+'" ondblclick="delimg('+id+')" style="margin-right:5px;">')

                    $('.layui-upload-list').append('<input type="hidden" name="top_pic" class="image'+id2+'"  value="'+res.data.src+'" lay-verify="required">')
                    id2 += 1;
                }
                if(res.code < 1){
                    layer.msg('上传失败', {icon: 1});
                }

                //上传成功的一些操作
                //……
                $('#demoText').html(''); //置空上传失败的状态
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
            //进度条
            ,progress: function(n, elem, e){
                element.progress('demo', n + '%'); //可配合 layui 进度条元素使用
                if(n == 100){
                    layer.msg('上传完毕', {icon: 1});
                }
            }
        });


        form.on('submit(add)', function (data) {
            console.log(data.field);
            $.ajax({
                'url': '/service/boxeteam',
                'type': 'post',
                'data': data.field,
                'dataType': 'json',
                success: function (data) {
                    if (data.code == 1) {
                        layer.msg(data.msg, {
                            icon: 6,
                            time: 800,
                        }, function () {
                            window.parent.location.href = data.url;
                        })
                    } else if (data.code == 0) {
                        layer.msg(data.msg);
                    }
                }
            });
        });

    });


</script>

{include file="common/_bottom"}